var BaseResetPwd = app.controller('BaseResetPwd', function($rootScope,$scope,$http,BaseResetPwdData) {
	try{
		$rootScope.showf=false;
		$scope.show = false;
		$scope.busy = false;
		$scope.dobusy=false;
		$rootScope.code_value = '获取验证码';
		$rootScope.title = '设置新密码';

		var url=SITE_URL+"index.php?app=baseloginapp&callback=JSON_CALLBACK&act=userinfo";
		$http.jsonp(url).success(function(data) {
			$scope.tel=data.retval.phone_tel;
		});
		
		$scope.keyPress=function(e){
			if(e.which==13){
				$scope.setpassword();
			}
		}
		$scope.keyPressNext=function(e){
			if(e.which==13||e.which==9){
				$scope.setpassword();
			}
		}
		//验证密码规则
		$scope.checkpwd=function (pass){ 
			var ls = 0; 
			if(pass.match(/([a-z])+/)){  ls++; }  
			if(pass.match(/([0-9])+/)){  ls++; }  
			if(pass.match(/([A-Z])+/)){   ls++; }  
			if(pass.match(/[^a-zA-Z0-9]+/)){ ls++;}  
			return ls; 
		}  

		// 设置新密码
		$scope.setpassword = function() {
			if($scope.dobusy){
				return false;
			}
			if($scope.tel == ""){
				showtoast("请输入手机号码");
				return false;
			}

			var reg = /(^13\d{9}$)|(^14)[5,7]\d{8}$|(^15[0,1,2,3,5,6,7,8,9]\d{8}$)|(^17)[6,7,8]\d{8}$|(^18\d{9}$)/g ;  
			if(!reg.test($scope.tel)){  
				showtoast("请输入正确的手机");
				return false;
			} 

			if(!$scope.pwd){
				showtoast("请输入新密码");
				return false;
			}

			if($scope.pwd.length<6){
				showtoast("密码长度至少为6位");
				return false;
			}

			var reg = /^[0-9a-zA-Z]+$/;
			if(!reg.test($scope.pwd)||$scope.checkpwd($scope.pwd)<2){
				showtoast("密码必须为数字与字母混合");
				return false;
			}

			if($scope.d_pwd != $scope.pwd){
				showtoast("两次输入密码不相同，请重新输入");
				return false;
			}
			if(!$scope.validate_code){
				showtoast("请输入验证码");
				return false;
			}
			$scope.dobusy=true;
			var url=SITE_URL+"index.php?app=usermyapp&act=setpassword&tel="+$scope.tel+"&pwd="+$scope.pwd+"&callback=JSON_CALLBACK&code="+$scope.validate_code;
			$http.jsonp(url).success(function(data) {
				if(data.done){
					showtoast("新密码修改成功！");
					$rootScope.back();	
				}
				$scope.dobusy=false;
			}).error(function(){$scope.dobusy = false;});
		};

		$scope.get_code=function(){
			if($scope.busy){
				return false;
			}
			$scope.busy=true;
			var url=SITE_URL+"index.php?app=userapp&act=authcode&t="+$scope.tel+"&callback=JSON_CALLBACK&type=resetpwd";
			$http.jsonp(url).success(function(data) {
				if(data.done){

					$scope.code_num = 60;
					$rootScope.code_value = '秒后重发';
					var myTime = setInterval(function() {
						$scope.code_num--;
						$scope.$apply(); // 通知视图模型的变化

						if($scope.code_num==0){

							$scope.busy=false;
							$rootScope.code_value = '获取验证码';
							$scope.code_num =  '';
							clearInterval(myTime);
							$scope.$apply();
						}
					}, 1000);	
				}else{
					$scope.busy=false;
				}
			}).error(function(){$scope.busy = false;});
		}
	}
	catch (e) {
		showcatch(e);
	}
});
BaseResetPwd.BaseResetPwdData=function($q, $http,$stateParams,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
		}else{
			def.resolve(data);
		}

		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}